package cn.com.lsy.product.lepao.util;

import cn.com.lsy.product.lepao.common.Constant;
import cn.com.lsy.product.lepao.controller.base.BaseController;
import cn.com.lsy.product.lepao.model.entities.LpAdminTbl;
import org.apache.commons.lang.StringUtils;

/**
 * 验证用户token工具类
 *
 * @author huangke
 */
public class CheckTokenUtil {

    /**
     * 验证token是否正确
     *
     * @param token
     * @return
     */
    public static String check(String token, String roleType) {

        String status = "0";

        if (!StringUtils.isEmpty(token)) {

            BaseController baseController = new BaseController();
            LpAdminTbl userInfo = baseController.getUserInfo(token, roleType);
            if (userInfo != null) {

                if (userInfo.getStatus().equals(Constant.status.enable)) {
                    status = "1";
                } else {
                    status = "-1";
                }
            }
        }

        return status;
    }

}
